﻿@model AutomatedTestDataManagement.Models.TestStep

@{
    ViewBag.Title = "Edit";
}

<h2>Edit Test Step</h2>


@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>TestStep</legend>

        @Html.HiddenFor(model => model.TestStepID)
        @if (ViewBag.TestID != null)
        {
            <input type="hidden" name="TestID" id="TestID" value="@ViewBag.TestID" />
        } 
        @if (ViewBag.ScenarioID != null)
        {
            <input type="hidden" name="ScenarioID" id="ScenarioID" value="@ViewBag.ScenarioID" />
        }
        @if (ViewBag.SuiteID != null)
        {
            <input type="hidden" name="SuiteID" id="SuiteID" value="@ViewBag.SuiteID" />
        }


        <div class="editor-label">
            @Html.Label("Description")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.StepDescription)
            @Html.ValidationMessageFor(model => model.StepDescription)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.StepKindID, "Step Kind")
        </div>
        <div class="editor-field">
            @Html.DropDownList("StepKindID", null, new  { onchange = "FetchData();"} )
            @Html.ValidationMessageFor(model => model.StepKindID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DataID, "Linked Data Record")
        </div>
        <div class="editor-field">
                <select id="DataID" name="DataID" data-bind="options: DataID, optionsText: 'Value', optionsValue: 'Text', optionsCaption: ' -- Please select a test step -- ', value: SelectedDataID">
                </select>
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @if (ViewBag.TestID != null)
    {
        if (ViewBag.ScenarioID != null)
        {
            if (ViewBag.SuiteID != null)
            {
                // need to use all three in the link
                @Html.ActionLink("Return to Test", "Edit", "Test", new { id = ViewBag.TestID, scenarioID = ViewBag.ScenarioID, suiteID = ViewBag.suiteID }, null) @Html.Encode(" | ")
            }
            else
            {
                // use  test and scenario only
                @Html.ActionLink("Return to Test", "Edit", "Test", new { id = ViewBag.TestID, scenarioID = ViewBag.ScenarioID }, null) @Html.Encode(" | ")
            }
        }
        else
        {
            // only need the test id
            @Html.ActionLink("Return to Test", "Edit", "Test", new { id = ViewBag.TestID }, null) @Html.Encode(" | ")
        }
    }
    @Html.Partial("_TestSuiteNav")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script>document.addEventListener('DOMContentLoaded', FetchData(@Model.DataID), false);</script>
    
}

